﻿using CoolEngine.Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using CoolEngine.Engine.Scripting;
using CoolEngine;

namespace CoolEngineTest
{
    
    
    /// <summary>
    ///This is a test class for CameraTest and is intended
    ///to contain all CameraTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CameraTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for LookAt
        ///</summary>
        [TestMethod()]
        public void LookAtTest1()
        {
            Game game = null;
            Camera target = new Camera(game); 
            float x = 1F; 
            float y = 4F; 
            float z = -3F;
            target.LookAt(x, y, z);
            Vector3 expected = new Vector3(x,y,z);
            expected.Normalize();
            Assert.AreEqual(expected, target.Target);
        }

        /// <summary>
        ///A test for LookAt
        ///</summary>
        [TestMethod()]
        public void LookAtTest()
        {
            Game game = null;
            Camera target = new Camera(game);
            float x = 1F;
            float y = 4F;
            float z = -3F;
            Vector3 expected = new Vector3(x, y, z);
            target.LookAt(expected);            
            expected.Normalize();
            Assert.AreEqual(expected, target.Target);
        }

        /// <summary>
        ///A test for Pan
        ///</summary>
        [TestMethod()]
        public void PanTest()
        {
            Game game = null;
            Camera target = new Camera(game);
            target.LookAt(Vector3.Right);            
            target.Pan(MathHelper.Pi);
            float x = target.Target.X;
            float y = target.Target.Y;
            float z = target.Target.Z;
            Assert.AreEqual(Vector3.Left.X, x, 0.00001f, "Not looking in the right direction.");
            Assert.AreEqual(Vector3.Left.Y, y, 0.00001f, "Not looking in the right direction.");
            Assert.AreEqual(Vector3.Left.Z, z, 0.00001f, "Not looking in the right direction.");
        }
        /// <summary>
        ///A test for Pan
        ///</summary>
        [TestMethod()]
        public void PanTest2()
        {
            Game game = null;
            Camera target = new Camera(game);
            target.LookAt(Vector3.One);
            target.Pan(MathHelper.Pi);
            float x = target.Target.X;
            float y = target.Target.Y;
            float z = target.Target.Z;
            Vector3 oneNormal = Vector3.One;
            oneNormal.Normalize();
            Assert.AreEqual(-(oneNormal.X), x, 0.00001f, "Not looking in the right direction.");
            Assert.AreEqual(oneNormal.Y, y, 0.00001f, "Not looking in the right direction.");
            Assert.AreEqual(-(oneNormal.Z), z, 0.00001f, "Not looking in the right direction.");
        }
        /// <summary>
        ///A test for Position
        ///</summary>
        [TestMethod()]
        public void PositionTest()
        {
            Game game = null;
            Camera target = new Camera(game); 
            Vector3 expected = Vector3.One;
            Vector3 actual;
            target.Position = expected;
            actual = target.Position;
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///A test for Position
        ///</summary>
        [TestMethod()]
        public void MoveToFromScript()
        {
            Game game = new CoolGame();
            
            Camera target = new Camera(game);

            ScriptManager.RunCommand("import Camera\nfrom Microsoft.Xna.Framework import Vector3\nCamera.MoveTo(Vector3(1,1,1))");

            Vector3 expected = Vector3.One;
            Vector3 actual= target.Position;
            Assert.AreEqual(expected, actual);
        }
    }
}
